package com.example.work_2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

public class Activity2 extends AppCompatActivity {
    //Button button = findViewById(R.id.button2);

    static int i = 0;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_2);
        Button button1 = findViewById(R.id.button1);
        Button button2 = findViewById(R.id.button2);
        Log.i("Activity2","onCreate()");

       //按钮进行监听
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
           public void onClick(View v) {
                //监听按钮，如果点击，就跳转
               Intent intent = new Intent();
                //前一个（MainActivity.this）是目前页面，后面一个是要跳转的下一个页面
               intent.setClass(Activity2.this,reultactivity.class);
                i++;
                startActivity(intent);
                Log.i("reultactivity","onClick()");
           }
        });
        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //监听按钮，如果点击，就跳转
                Intent intent = new Intent();
                //前一个（MainActivity.this）是目前页面，后面一个是要跳转的下一个页面
                intent.setClass(Activity2.this,reultactivity.class);
                i--;
                if(i<0)
                    i=0;
                startActivity(intent);
                Log.i("reultactivity","onClick()");
            }
        });
    }

}